package com.nf.health.app.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.models.DetectionProject;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class DoctorDetectionAdapter extends BaseAdapter {
	private List<DetectionProject> projects;
	private int itemWidth;
	public DoctorDetectionAdapter(List<DetectionProject> projects, int itemWidth) {
		this.itemWidth = itemWidth;
		this.projects = projects;
	}
	@Override
	public int getCount() {
		return projects==null?0:projects.size();
	}

	@Override
	public Object getItem(int position) {
		return projects.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DetectionProject item = projects.get(position);
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_grid_doc_detection, position);
		holder.getConvertView().setLayoutParams(new LayoutParams(itemWidth, LayoutParams.WRAP_CONTENT));
		ImageView iv = holder.getView(R.id.iv);
		ImageView iv_bk = holder.getView(R.id.iv_bk);
		holder.setText(R.id.tv_name, item.getName());
		ImageLoaderUtils.getinstance(parent.getContext()).getImageNoDefault(iv, item.getImg());
		switch (item.getmStatus()) {
		case DetectionProject.STATUS_NONE:
			iv_bk.setBackgroundResource(R.drawable.circle_shape_bg_none);
			break;
		case DetectionProject.STATUS_GOING:
			iv_bk.setBackgroundResource(R.drawable.circle_shape_bg_going);
			break;
		case DetectionProject.STATUS_OK:
			iv_bk.setBackgroundResource(R.drawable.circle_shape_bg_ok);
			break;

		default:
			break;
		}
		return holder.getConvertView();
	}
	
}
